package com.deep.transaction.demo.runner;

import com.deep.transaction.demo.entity.Staff;
import com.deep.transaction.demo.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.Arrays;

//@Component
public class StaffRunner implements CommandLineRunner {

    @Autowired
    private StaffService staffService;

    @Override
    public void run(String... strings) throws Exception {

        try {
            Staff Staff1 = new Staff("Peter", "Ops", 12000L);
            Staff Staff2 = new Staff("Sam", "Tech", 22000L);
            staffService.insert(Arrays.asList(
                    Staff1, Staff2
            ));
        } catch (RuntimeException exception) {
            System.out.println("Exception in batch 1...!" + exception.getMessage());
        }


        try {
            Staff Staff3 = new Staff("Ryan King", "Tech", 32000L);
            Staff Staff4 = new Staff("Nick", "Ops", 18000L);
            staffService.insert(Arrays.asList(
                    Staff3, Staff4
            ));
        } catch (RuntimeException exception) {
            System.out.println("Exception in batch 2...!" + exception.getMessage());
        }
        System.out.println(staffService.getStaffs());
    }
}
